package com.example.tests;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import org.testng.annotations.Test;
import com.example.utils.SortedListOf;

public class ContactRemovalTests extends TestBase {
	
	@Test
	public void deleteSomeContact(){
		// save current list of contacts
//		SortedListOf<ContactData> oldList = new SortedListOf<ContactData>(app.getHibernateHelper().listContacts());
		SortedListOf<ContactData> oldList = app.getModelContacts().getContacts();

	 	int index = app.getContactHelper().getRandomContactIndex(oldList);
	 	
	 	if (index > 0) {
			app.getContactHelper().deleteContact(index);
			
		 	// save updated list of contacts
//			SortedListOf<ContactData> newList = app.getContactHelper().getUiContacts();
			SortedListOf<ContactData> newList = app.getModelContacts().getContacts();
		 	
		 	// update oldList with the same data
		  assertThat(newList, equalTo(oldList));
		  
	    // compare model to implementation
      if ("yes".equals(app.getProperty("check.db"))) {
        assertThat(app.getModelContacts().getContacts(), equalTo(app.getHibernateHelper().listContacts()));
        System.out.println("DB check done. On contact: " + index);
      }
      
      if ("yes".equals(app.getProperty("check.ui"))) {
        assertThat(app.getModelContacts().getContacts(), equalTo(app.getContactHelper().getUiContacts()));
        System.out.println("UI check done. On contact: " + index);
      }
	 	}
	}

}
